home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / MacMemory.c < prev    next >
Text File  |  1995-07-27  |  1KB  |  47 lines

  1. /* 
  2. MacMemory.c
  3.  
  4. This is meant to be used in association with MacMemory.h, which redefines the
  5. Standard C memory allocation functions to be implemented directly as calls to
  6. the Macintosh Memory Manager. So don't write programs that explicitly call
  7. "MacRealloc". This is for portable C programs that call "realloc", but which
  8. will be compiled to use MacRealloc instead, for best performance on the Mac.
  9.  
  10. You use MacMemory.h by adding the line
  11. #include "MacMemory.h"
  12. either to your THINK/CodeWarrior C project prefix or to some header file that you 
  13. include in all your files.
  14.  
  15. HISTORY:
  16. 10/25/94 dgp deleted MacMemset() because it's no longer needed. CodeWarrior 4.5 works fine.
  17. */
  18. #include "MacMemory.h"
  19. #ifndef _STDLIB
  20.     #include <stdlib.h>
  21. #endif
  22. #ifndef _STDIO
  23.     #include <stdio.h>
  24. #endif
  25. #ifndef _STRING
  26.     #include <string.h>
  27. #endif
  28. #ifndef __MEMORY__
  29.     #include <Memory.h>
  30. #endif
  31.  
  32. void *MacRealloc(void *oldPtr,size_t size)
  33. {
  34.     void *newPtr;
  35.     
  36.     if(oldPtr==NULL)return NewPtr(size);
  37.     SetPtrSize(oldPtr,size);
  38.     if(MemError()){
  39.         newPtr=NewPtr(size);
  40.         if(newPtr==NULL)return newPtr;
  41.         memcpy(newPtr,oldPtr,size);
  42.         DisposPtr(oldPtr);
  43.     }else newPtr=oldPtr;
  44.     return newPtr;
  45. }
  46.  
  47.